/*    */ package com.newcrm.businessarchives;
/*    */ 
/*    */ import com.newcrm.exception.CaptchaException;
/*    */ import com.newcrm.util.Util;
/*    */ import java.io.IOException;
/*    */ import java.io.PrintStream;
/*    */ import java.util.Date;
/*    */ import java.util.HashMap;
/*    */ import java.util.Map;
/*    */ import org.apache.log4j.Logger;
/*    */ import org.jsoup.Connection;
/*    */ import org.jsoup.Connection.Method;
/*    */ import org.jsoup.Connection.Response;
/*    */ import org.jsoup.Jsoup;
/*    */ import org.jsoup.nodes.Document;
/*    */ import org.jsoup.nodes.Element;
/*    */ import org.jsoup.select.Elements;
/*    */ 
/*    */ public class NanjingSearchEngine extends SearchEngine
/*    */ {
/* 21 */   private static Logger logger = Logger.getLogger(NanjingSearchEngine.class
/* 22 */     .getName());
/*    */ 
/* 24 */   private Map<String, String> params = new HashMap();
/*    */ 
/*    */   public NanjingSearchEngine(String name) {
/* 27 */     this.name = standardizedName(name);
/* 28 */     this.params.put("企业名称", "CompanyName");
/* 29 */     this.params.put("企业注册号", "SN");
/* 30 */     this.params.put("法定代表人", "Header");
/* 31 */     this.params.put("住所", "Address");
/* 32 */     this.params.put("注册资本", "RegisteredCapital");
/* 33 */     this.params.put("企业状态", "AnnualinSpectionResult");
/* 34 */     this.params.put("企业类型", "CompanyType");
/* 35 */     this.params.put("成立日期", "FoundedDate");
/* 36 */     this.params.put("经营期限", "OperatingPeriod");
/* 37 */     this.params.put("登记机关", "RegistrationAuthority");
/* 38 */     this.params.put("经营范围", "BusinessScope");
/*    */   }
/*    */ 
/*    */   public static void main(String[] args) throws CaptchaException {
/* 42 */     NanjingSearchEngine searcher = new NanjingSearchEngine(
/* 43 */       "南京亚新房地产营销策划有限公司");
/* 44 */     System.out.println(searcher.getCompanyByWeb());
/*    */   }
/*    */ 
/*    */   protected Map<String, Object> getCompanyByWeb() throws CaptchaException
/*    */   {
/* 49 */     if (!isValid(this.name)) {
/* 50 */       return null;
/*    */     }
/*    */     try
/*    */     {
/* 54 */       Connection.Response res = Jsoup.connect("http://www.njgs.gov.cn/CorpQuery")
/* 55 */         .data("txtCorpName1", this.name).method(Connection.Method.POST)
/* 56 */         .userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)").timeout(60000).execute();
/*    */ 
/* 58 */       Document doc = res.parse();
/* 59 */       Elements links = doc.select("tr[class=qycx2] td a");
/* 60 */       String detailUrl = null;
/* 61 */       if ((links != null) && (links.size() >= 1)) {
/* 62 */         detailUrl = links.get(0).absUrl("href");
/*    */       }
/*    */ 
/* 65 */       if ((detailUrl == null) || (detailUrl.trim().length() == 0))
/*    */       {
/* 67 */         JiangsuSearchEngine searchEngine = new JiangsuSearchEngine(
/* 68 */           this.name);
/* 69 */         return searchEngine.getCompanyByWeb();
/*    */       }
/*    */ 
/* 72 */       doc = Jsoup.connect(detailUrl).userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)").timeout(10000)
/* 73 */         .get();
/* 74 */       links = doc.select("table th");
/* 75 */       if (links == null) {
/* 76 */         return null;
/*    */       }
/* 78 */       Map info = new HashMap();
/* 79 */       for (Element item : links) {
/* 80 */         String key = item.text().trim();
/* 81 */         if (this.params.containsKey(key))
/*    */         {
/* 84 */           info.put((String)this.params.get(key), item.nextElementSibling().text());
/*    */         }
/*    */       }
/* 87 */       info.put("UpdateDate", Util.date2Str(new Date()));
/* 88 */       if (info.size() > 1)
/*    */       {
/* 90 */         saveDB(info);
/*    */       }
/*    */ 
/* 93 */       return info;
/*    */     } catch (IOException e) {
/* 95 */       logger.warn("get company from web failed", e);
/*    */     }
/* 97 */     return null;
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.businessarchives.NanjingSearchEngine
 * JD-Core Version:    0.6.1
 */